<?php
/**
 * User
 *-------------------------
 *
 * Model user, all functions to deal with user add, change, delete 
 *
 * PHP versions 5
 *
 * LICENSE: This source file is from Smarter Ver4.0, which is a comprehensive shopping engine
 * that helps consumers to make smarter buying decisions online. We empower consumers to compare
 * the attributes of over one million products in the computer and consumer electronics categories
 * and to read user product reviews in order to make informed purchase decisions. Consumers can then
 * research the latest promotional and pricing information on products listed at a wide selection of
 * online merchants, and read user reviews on those merchants.
 * The copyrights is reserved by http://www.mezimedia.com.
 * Copyright (c) 2005, Mezimedia. All rights reserved.
 *
 * @author     kevin cheng<kevin_cheng@mezimedia.com>
 * @copyright  (C) 2004-2008 Mezimedia.com
 * @license    http://www.mezimedia.com  PHP License 5.2
 * @version    CVS: $Id: UserController.php
 * @link       http://pms.mezimedia.com/
 * @deprecated File deprecated in Release 1.0
 */

class Role extends Zend_Db_Table
{	
	public $_db = null;
	public $_filter_list =array();	
	public $_totalCount;
	private $sqlFilter = "";
	
	/*
	 * set the db handle by fetching from register
	 * init the db table setting 
	 * 
	 */
	public function __construct () {
		$this->_db = Zend_Registry :: get('db_adapter');
		$this->_name = 'tt_role';
		$this->_primary = 'id';
		parent::_setup();
	}
	
	/*
	 * get role list from role, together with role, role
	 * 
	 * @param string $arg1  the string to quote
     *
     * @return array role info               
     * @throws db error or exceptions
     * @access protected    
	 */
	function getFullRoleList($where=array(), $order='', $from=0, $size=20){		
		if($where['name'] !=""){
			$this->sqlFilter .= "And t.name like '%".$where['name']."%' "; 
		}
		//$this->sqlFilter = $sqlFilter;
		
		$roleList = array();
		$rs = $this->_db->query('select SQL_CALC_FOUND_ROWS t.id as roleId, t.name as roleName, t.description, t.create_time, t.flag from tt_role t where t.flag=1 '.$this->sqlFilter.' order by '.$order.' limit '.$from.",".$size);		
		if ($rs) {
			$roleList= $rs->fetchAll();											
		}
		$totalCountRS = $this->_db->query('SELECT FOUND_ROWS() as count');
		$count = $totalCountRS->fetchAll();		
		$this->_totalCount = $count[0]["count"];
		return $roleList;
	}
	
	/*get a role's basic info */
	function getRole($roleId){
		$rs = $this->_db->query('select t.id as roleId, t.name as roleName, t.description,t.create_time, t.flag from tt_role t where t.id='.$roleId);		
		if ($rs) {
			$role= $rs->fetchAll();												
		}		
		return $role[0]; 
	}
	
	function findRole($where)
	{
		$rs = $this->_db->query('select * from tt_role t where '.$where);
		return $rs->fetchAll();
	}
	
}
?>
